<template>
  <iep-dialog :dialog-show="dialogShow" :title="`${methodName}字典`" width="500px" @close="close">
    <el-form class="form-detail" :model="form" ref="form" size="small" label-width="100px">
      <iep-form-item class="form-half" label-name="字典值" prop="value">
        <el-input v-model="form.value"></el-input>
      </iep-form-item>
      <iep-form-item class="form-half" label-name="字典名" prop="label">
        <el-input v-model="form.label"></el-input>
      </iep-form-item>
      <iep-form-item class="form-half" label-name="排序" prop="sort">
        <el-input v-model="form.sort"></el-input>
      </iep-form-item>
    </el-form>
    <template slot="footer">
      <operation-wrapper>
        <iep-button type="primary" @click="handleSubmit()">保存</iep-button>
      </operation-wrapper>
    </template>
  </iep-dialog>
</template>
<script>
import { _initRow } from './options'
import { postChild, putChild } from '@/api/dict'
export default {
  data () {
    return {
      dialogShow: false,
      form: _initRow(),
      methodName: '新增'
    }
  },
  methods: {
    handleSubmit () {
      let submitChild = null
      if (this.form.id) {
        submitChild = putChild
      } else {
        submitChild = postChild
      }
      delete this.form.createTime
      delete this.form.updateTime
      this.$http({
        url: this.$http.adornUrl(submitChild().url),
        method: submitChild().method,
        data: this.form
      }).then(() => {
        this.close()
      })
    },
    close () {
      this.dialogShow = false
      this.$emit('load-page')
    }
  }
}
</script>
